package com.jzo2o.foundations.controller.operation;


import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags="运营端-区域服务相关接口")
public class ServeController {

    @Autowired
    private IServeService serveService;

    /**
     * 区域服务分页
     * @param servePageQueryReqDTO
     * @return
     */
    @GetMapping("/page")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO){
        return serveService.page(servePageQueryReqDTO);
    }

    /**
     * 区域服务添加功能
     */
    @PostMapping("/batch")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList){
        serveService.batchAdd(serveUpsertReqDTOList);
    }

    /**
     * 修改价格
     */
    @PutMapping("/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "服务id",required =true,dataTypeClass = Long.class),
            @ApiImplicitParam(name="price",value = "价格",required = true,dataTypeClass = BigDecimal.class )
    })
    public  void update( @PathVariable("id")Long id,
    @RequestParam("price" )BigDecimal price){
        serveService.update(id,price);
    }

    /**
     * 服务上架
     */

    @PutMapping("/onSale/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "服务id",required = true,dataTypeClass = Long.class)
    })
    public void onSale(@PathVariable("id") Long id){
        serveService.onSale(id);
    }
    /**
     * 删除区域服务
     *
     */

    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable("id") Long id){
        serveService.deleteById(id);
    }

    /**
     * 服务下架
     */

    @PutMapping("/offSale/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "服务id",required = true,dataTypeClass = Long.class)
    })
    public void offSale(@PathVariable("id") Long id){
        serveService.offSale(id);
    }

   @PutMapping("/onHot/{id}")
        public void onHot(@PathVariable("id")Long id){
        serveService.onHot(id);
    }

    @PutMapping("/offHot/{id}")
    public void onHotuploded(@PathVariable("id")Long id){
        serveService.onHotuploded(id);
    }

}
